package cn.moefly.sample.utils;

import com.google.common.base.CaseFormat;
import org.springframework.util.StringUtils;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;

/**
 * 记录一些随手写的无用代码
 */
public class UselessCodeUtils {

    /**
     * 把一个类里面的字段遍历打印成一些想要的格式
     * @param clazz
     */
    public static void pringFieldToName(Class<?> clazz){
        Set<String> set = Set.of("serialVersionUID", "id");
        Arrays.stream(clazz.getDeclaredFields()).map(Field::getName).filter(Predicate.not(set::contains)).forEach(name->{
            String to = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
            Optional<String> reduce = Arrays.stream(to.split("_")).map(StringUtils::capitalize).reduce((s1, s2) -> s1 + " " + s2);
            System.out.println(String.format("Map.entry(\"%s\",\"%s\"),",name, reduce.get()));
        });
    };
}
